package com.doit.day01;

import org.apache.kafka.common.Cluster;

import java.util.Map;

public class MyPartitioner implements org.apache.kafka.clients.producer.Partitioner{
    /**
     * 具体的分区方法
     * @param topic
     * @param key
     * @param keyBytes
     * @param value
     * @param valueBytes
     * @param cluster
     * @return
     */
    @Override
    public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) {
        String s = value.toString();
        boolean flag = s.startsWith("b");
        if (flag){
            return 0;
        }else if(s.startsWith("w")){
            return 1;
        }else if(s.startsWith("h")){
            return 2;
        }else{
            return 3;
        }
    }

    @Override
    public void close() {

    }

    @Override
    public void configure(Map<String, ?> configs) {

    }
}
